<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #outerContainer{
            width: 100px;
            height: 100px;
            background-color: blue;
        }
        #innerContainer{
            width: 50px;
            height: 50px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="outerContainer">
        <div id="innerContainer"></div>
    </div>
    <script>
        const outer = document.getElementById("outerContainer");
        const inner = document.getElementById("innerContainer");
        // addEventListener注册的事件响应方式一般是冒泡 也就是当触发多个点击事件时 会先从当前DOM元素向上响应触发
        // 传入的第三个参数可以决定响应方式 true为捕获(从顶部到下面) false为冒泡(默认值)
        outer.addEventListener("click",() => {
            console.log("This is outer");
        },true);

        inner.addEventListener("click",() => {
            console.log("This is inner");
        });

        document.addEventListener("click",() => {
            console.log("This is document");
        },false);
        // 冒泡方式结果
        // This is inner
        // This is outer
        // This is document
    </script>
</body>
</html>